package jdos.cpu.core_normal;

import jdos.cpu.CPU;
import jdos.cpu.CPU_Regs;
import jdos.cpu.Instructions;
import jdos.hardware.Memory;

public class Prefix_helpers extends Instructions {
    static public abstract class OP {
        public abstract int call();
        public String toString() {
        	return "";
        }
    }
    static public abstract class PREFIX {
        public abstract void call();
    }
    static protected final int[] AddrMaskTable1={0x0000ffff,0xffffffff};

    protected static final int OPCODE_NONE=0x000;
    protected static final int OPCODE_0F=0x100;

    public static final int ILLEGAL_OPCODE = 1;
    public static final int NOT_HANDLED = 2;
    public static final int HANDLED = 3;
    public static final int CBRET_NONE = 5;
    public static final int CONTINUE = 6;
    public static final int RETURN = 7;
    public static final int DECODE_END = 8;

    public static int RUNEXCEPTION() {
        CPU.CPU_Exception(CPU.cpu.exception.which,CPU.cpu.exception.error);
        return CONTINUE;
    }

    public static int EXCEPTION(int blah) {
        CPU.CPU_Exception(blah);
        return CONTINUE;
    }

    public static int GETIP() {
        return (cseip- CPU_Regs.reg_csPhys);
    }

    static public void SAVEIP() {
        CPU_Regs.reg_eip=GETIP();
        //System.out.println("SAVEIP: "+CPU_Regs.reg_eip);
    }

    static public void LOADIP() {
        cseip=CPU_Regs.reg_csPhys+CPU_Regs.reg_eip;
        //System.out.println("LOADIP: "+cseip);
    }

    protected static void JumpCond16_b(boolean COND) {
        if (COND) {
            int offset = Fetchbs();
            SAVEIP();
            reg_ip(reg_ip()+offset);
        } else {
            SAVEIP();
            reg_ip(reg_ip()+1);
        }
    }

    protected static void JumpCond32_b(boolean COND) {
        if (COND) {
            int offset = Fetchbs();
            SAVEIP();
            reg_eip+=offset;
        } else {
            SAVEIP();
            reg_eip++;
        }
    }

    protected static void JumpCond16_w(boolean COND) {
        if (COND) {
            int offset = Fetchws();
            SAVEIP();
            reg_ip(reg_ip()+offset);
        } else {
            SAVEIP();
            reg_ip(reg_ip()+2);
        }
    }

    protected static void JumpCond32_d(boolean COND) {
        if (COND) {
            int offset = Fetchds();
            SAVEIP();
            reg_eip+=offset;
        } else {
            SAVEIP();
            reg_eip+=4;
        }
    }
    
}
